import redis
REDIS_URL = "redis://10.62.170.203:6379"

def check_redis_keys():
    r = redis.Redis.from_url(REDIS_URL)
    pattern = "folder:dupefilter:*"
    cursor = "0"
    keys_found = []
    while cursor != 0:
        cursor, partial_keys = r.scan(
            cursor=int(cursor), 
            match=pattern,
            count=100
        )
        keys_found.extend(partial_keys)
        print(f"已经找到{len(keys_found)}个匹配键")
    
    if not keys_found:
        print("未找到残留的键")
    else:
        print("发现残留的键：")
        for key in keys_found:
            print(f" - {key.decode('utf-8')}")
        print(f"总共{len(keys_found)}个键需要清理")


if __name__ == "__main__":
    check_redis_keys()
